#import "LoadingViewController.h"
#import "ArcTabViewController.h"
#import "Constants.h"

#pragma mark - Class Extension
@interface LoadingViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *animationImageView;
@property (weak, nonatomic) IBOutlet UIImageView *letsRockImageView;
//@property UINavigationController* navigation;

@end

#pragma mark - Implementation
@implementation LoadingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.animationImageView.image = [UIImage imageNamed:@"Loading_Picture_1.jpg"];
    
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:YES];
    [self playLoadingAnimation];
    
}

-(void)addGestureRecogniser:(UIView *)touchView{
    UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(advanceToSongTable)];
    [touchView addGestureRecognizer:singleTap];
}

-(void)advanceToSongTable{
    
    ArcTabViewController * arcTabViewController = [[ArcTabViewController alloc] initWithTitle:@"KYArcTab"
                                                                                   tabBarSize:(CGSize){kKYTabBarWdith, kKYTabBarHeight}
                                                                        tabBarBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:kKYITabBarBackground]]
                                                                                     itemSize:(CGSize){kKYTabBarItemWidth, kKYTabBarItemHeight}
                                                                                        arrow:[UIImage imageNamed:kKYITabBarArrow]];
    [self presentViewController:arcTabViewController animated:YES completion:NULL];
    
}


-(void)playLoadingAnimation{
    [UIView transitionWithView:self.animationImageView
                      duration:1.2f
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        
                        sleep(1.0);
                        self.animationImageView.image = [UIImage imageNamed:@"Loading_Picture_11.jpg"];
                        
                    } completion:^(BOOL finished) {
                        [UIView transitionWithView:self.animationImageView
                                          duration:1.2f
                                           options:UIViewAnimationOptionTransitionCrossDissolve
                                        animations:^{
                                            self.animationImageView.image = [UIImage imageNamed:@"Loading_Picture_12.jpg"];
                                            [self.letsRockImageView setAlpha:0.8];
                                        } completion:^(BOOL finished) {
                                            
                                            [self addGestureRecogniser:self.view];
                                            [UIView animateWithDuration:0.5
                                                                  delay:0.1
                                                                options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
                                                                    [self.letsRockImageView setAlpha:0.2];
                                                                } completion:nil];
                                        }];
                    }];
}

@end
